//
//  MenuViewController.m
//  ZFHorizontalMenuView
//
//  Created by linzaifei on 2021/9/3.
//

#import "MenuViewController.h"
#import "ZFHorizontalMenuView.h"
#import "colors.h"
@interface MenuViewController ()<ZFHorizontalMenuViewDataSource,ZFHorizontalMenuViewDelegate>

@end

@implementation MenuViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithHexLightColor:COLOR_BG darkColor:COLOR_BG];
    [self createView];
    

    
}

-(void)createView{
    ZFHorizontalMenuView *horizontalMenuView = [[ZFHorizontalMenuView alloc] init];
    horizontalMenuView.dataSource = self;
    horizontalMenuView.delegate = self;
    horizontalMenuView.isNeedAnimation = YES;
    horizontalMenuView.minimumLineSpacing = 5;
    horizontalMenuView.minimumInteritemSpacing = 0;
    horizontalMenuView.pageControlView.defaultConfig.currentPageIndicatorTintColor = [UIColor redColor];
    horizontalMenuView.pageControlView.defaultConfig.pageIndicatorTintColor = [UIColor grayColor];
    horizontalMenuView.pageControlView.defaultConfig.size = CGSizeMake(20, 4);
    horizontalMenuView.pageControlView.defaultConfig.space = 20;
    horizontalMenuView.pageControlView.style = ZFHorizontalMenuViewPageControlStyleAnimated;
    horizontalMenuView.pageControlView.aliment = ZFHorizontalMenuViewPageControlAlimentCenter;
    horizontalMenuView.contentInset = UIEdgeInsetsMake(5, 5, 5, 5);
    
    [self.view addSubview:horizontalMenuView];

    horizontalMenuView.translatesAutoresizingMaskIntoConstraints = NO;
    
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-10-[horizontalMenuView]-10-|" options:0 metrics:0 views:@{@"horizontalMenuView":horizontalMenuView}]];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:horizontalMenuView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1 constant:100]];
    [horizontalMenuView reloadData];
}
///需要显示的个数
- (NSInteger)zf_horizontalMenuView:(ZFHorizontalMenuView *)horizontalMenuView{
    return 20;
}
////对应每一个title
-(NSString *)zf_horizontalMenuView:(ZFHorizontalMenuView *)horizontalMenuView titleForItemAtIndex:(NSInteger)index{
    return @"测试数据";
}
- (NSURL *)zf_horizontalMenuView:(ZFHorizontalMenuView *)horizontalMenuView urlForItemAtIndex:(NSInteger)index{
    return [NSURL URLWithString:@"https://img2.baidu.com/it/u=1814561676,2470063876&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1704474000&t=850eded50f38c64ee470522d02a40f1c"];
}

-(NSInteger )zf_numOfPageRowsInHorizontalMenuView:(ZFHorizontalMenuView *)horizontalMenuView{
    return 2;
}
-(NSInteger )zf_numOfPageColumnsInHorizontalMenuView:(ZFHorizontalMenuView *)horizontalMenuView{
    return 5;
}
-(CGSize)zf_imageSizeInHorizontalMenuView:(ZFHorizontalMenuView *)horizontalMenuView{
    return  CGSizeMake(48, 48);
}

-(void)zf_horizontalMenuView:(ZFHorizontalMenuView *)horizontalMenuView didSelectItemAtIndexPath:(NSInteger )index{
    NSLog(@"%ld",index);
}

@end
